<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	{{--<meta name="viewport" content="width=device-width, initial-scale=1">--}}
	<title>木投网--找回密码</title>
	<link rel="stylesheet" href="/resource/css/mt_index.css">
	<link rel="stylesheet" href="/resource/css/mt_login.css">
</head>
<body>
<div class="login-head register-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<span>找回密码</span>
		</div>
	</div>
</div>
<div class="register-body pass-body main">
	<form action="modify_pwd" method="post" class="form"  onsubmit="return check_all()">
		<div class="form-group">
			<label for=""><i>*</i>手机号</label>
			<input type="text" class="form-control" placeholder="请输入正确的手机号码" id="mobile" name="mobile">
			<i class="i i-tel"></i>
			<span>手机号错误</span>
		</div>
		<div class="form-group form-code">
			<label for=""><i>*</i>验证码</label>
			<input type="text" class="form-control"  name="captcha" id="captcha" onblur="check_captcha()"><span id="t_captcha">验证码错误</span>
			<div style="margin-left: 8px;float:left;">
				<img onclick="this.src='/captcha?'+ Math.random()"  src="/captcha" style="width:102px;height:38px;">
			</div>
		</div>
		<div class="form-group form-code">
			<label for=""><i>*</i>手机验证码</label>
			<input type="text" class="form-control" onblur="check_news()" id="news_captcha" placeholder="短信验证码">
			<button type="button" class="btn-code btn-code-zeor" id="f_captcha">获取验证码</button>
			<span id="t_news">请输入</span>
		</div>
		<div class="form-group">
			<label for=""><i>*</i>设置密码</label>
			<input type="password" class="form-control" placeholder="请输入密码" id='pwd' onblur="check_pwd()" name="password">
			<i class="i i-pass"></i>
			<span id="t_pwd">不能为空</span>
		</div>
		<div class="form-group">
			<label for=""><i>*</i>确认密码</label>
			<input type="password" class="form-control" placeholder="请确认新密码" id="pwd1" onblur="check_pwd1()">
			<i class="i i-pass"></i>
			<span id="t_pwd1">两次输入密码不一致</span>
		</div>
		<button type="submit" class="btn-login">提交</button>
	</form>
</div>
<div class="login-foot register-foot main">
	<div class="foot-info">
		<ul>
			<li><a href="javascript:;">关于我们</a><span>|</span></li>
			<li><a href="javascript:;">法律声明</a><span>|</span></li>
			<li><a href="javascript:;">诚聘英才</a><span>|</span></li>
			{{--<li><a href="javascript:;">投资洽谈</a><span>|</span></li>--}}
			<li><a href="javascript:;">联系我们</a><span>|</span></li>
			{{--<li><a href="javascript:;">常见问题</a></li>--}}
		</ul>
		<p>北京木投网科技有限公司 京ICP备15043001   Copyright © 2016  Mutouw.com 版权所有</p>
	</div>
</div>	

<script src="/resource/js/jquery-1.11.3.min.js"></script>
<script src="/resource/js/mt_index.js"></script>
<script>

	function check_captcha(){
		var captcha =  document.getElementById('captcha').value;
		var status = false;
		if(captcha){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						$("#t_captcha").hide();
						status = true
					} else {
						$("#t_captcha").show();
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_verify_register', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('captcha=' + captcha);
			return status
		}else{
			return false;
		}
	}
	//短信验证
	function check_news(){
		var news_captcha = document.getElementById('news_captcha').value;
		var mobile = document.getElementById('mobile').value;
		$("#t_news").show();
		var status = false;
		if(news_captcha){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						$("#t_news").hide();
						status = true
					}else if(ajax.responseText == 2){
						$("#t_news").html("验证码已过期");
					}else{
						$("#t_news").html("验证码错误");
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_verify_register', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('news_captcha=' + news_captcha + '&mobile=' +mobile);
			return status
		}else{
			document.getElementById('t_news').innerHTML = "<span style='color:red'>*</span>";
			return false;
		}

	}
	//获取短信验证码

	$('#f_captcha').bind('click',function foo(){
		var mobile = document.getElementById('mobile').value;
		var reg = /^1[34578]\d{9}$/;
		$("#t_news").show();
		if(reg.test(mobile)) {
			if(check_captcha()) {
				var wait = 60;
				var int = function fetch_captcha() {
					if (wait == 0) {
						$("#f_captcha").bind("click", foo);
						$('#f_captcha').html('获取验证码').addClass('btn-code-zeor');
						clearInterval(a)
						wait = 60;
					}
					else {
						$('#f_captcha').unbind("click", foo);
						$('#f_captcha').html("重新发送(" + wait + ")").removeClass('btn-code-zeor');
						wait--;
					}
				}
				var a = setInterval(int, 1000);
				$.ajax({
					url: "/verify_news",
					type: "POST",
					data: "mobile=" + mobile,
					success: function (msg) {
						if (msg == 10000) {
							$("#t_news").html("验证码发送成功,10分钟内输入有效");
						}else if(msg == 160040){
							$("#t_news").html("您当日验证码发送次数过多");
							window.clearInterval(a);//停止计时器
							$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
							$(".form-code span.code").html("获取短信验证码");
							return false;
						}else{
							$("#t_news").html("验证码发送错误");
							window.clearInterval(a);//停止计时器
							$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
							$(".form-code span.code").html("获取短信验证码");
							return false;
						}
					}
				});
			}else{
				$("#t_captcha").show();
				return false
			}
		}else{
			$("#t_news").html("请输入正确的手机号");
			return false
		}
	})

	//验证密码
	function check_pwd(){
		var pwd = $('#pwd').val();
		var reg=/^\w{6,16}$/;
		if(pwd){
			if(reg.test(pwd)) {
				$("#t_pwd").hide();
				return true
			}else{
				$("#t_pwd").show();
				$("#t_pwd").html("密码长度六位到十六位");
				return false
			}
		}else{
			$("#t_pwd").show();
			return false
		}
	}

	//验证新密码
	function check_pwd1(){
		var pwd  = $('#pwd').val();
		var pwd1 = $('#pwd1').val();
		if(pwd == pwd1){
				$("#t_pwd1").hide();
				return true
		}else{
			$("#t_pwd1").show();
			return false
		}
	}

	//检测全部
	function check_all(){
		return (check_pwd()&&check_news()&&check_pwd1())
	}
</script>
</body>
</html>